<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>tkinter模块 | MXY 1.0版Python整理</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../home/10.网络编程/1.网络编程.html" />
    
    
    <link rel="prev" href="../../home/8.面向对象/7.模块和包.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="9.1"
        data-chapter-title="tkinter模块"
        data-filepath="home/9.tkinter模块/tkinter模块.md"
        data-basepath="../.."
        data-revision="Mon Oct 22 2018 08:32:35 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        MXY整理版Python基础
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" >
            
            <span><b>1.</b> Python的安装和简介</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="home/1.Python的安装和简介/1.python基础知识.html">
            
                
                    <a href="../../home/1.Python的安装和简介/1.python基础知识.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        Python的基础知识
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="home/1.Python的安装和简介/2.python的安装及版本检测.html">
            
                
                    <a href="../../home/1.Python的安装和简介/2.python的安装及版本检测.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        Python安装及版本检测
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="home/1.Python的安装和简介/3.第一个python程序.html">
            
                
                    <a href="../../home/1.Python的安装和简介/3.第一个python程序.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        第一个Python程序
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" >
            
            <span><b>2.</b> Python的基本语法</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="home/2.Python的基本语法/1.注释及语句分类.html">
            
                
                    <a href="../../home/2.Python的基本语法/1.注释及语句分类.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        注释及语句分类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="home/2.Python的基本语法/2.命名方式和关键字.html">
            
                
                    <a href="../../home/2.Python的基本语法/2.命名方式和关键字.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        命名方式和关键字
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" >
            
            <span><b>3.</b> Python的变量及数据类型</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="home/3.变量和数据类型/1.变量.html">
            
                
                    <a href="../../home/3.变量和数据类型/1.变量.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="home/3.变量和数据类型/2.数据类型.html">
            
                
                    <a href="../../home/3.变量和数据类型/2.数据类型.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        数据类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="home/3.变量和数据类型/3.数据类型转换.html">
            
                
                    <a href="../../home/3.变量和数据类型/3.数据类型转换.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        数据类型转换
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="home/3.变量和数据类型/4.运算和运算符.html">
            
                
                    <a href="../../home/3.变量和数据类型/4.运算和运算符.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        数据类型转换
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" >
            
            <span><b>4.</b> Python的流程控制</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="home/4.流程控制/1.顺序结构和分支结构.html">
            
                
                    <a href="../../home/4.流程控制/1.顺序结构和分支结构.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        顺序结构和分支结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="home/4.流程控制/2.循环结构.html">
            
                
                    <a href="../../home/4.流程控制/2.循环结构.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        循环结构
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" >
            
            <span><b>5.</b> 函数及作用域</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="home/5.函数及作用域/1.函数.html">
            
                
                    <a href="../../home/5.函数及作用域/1.函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="home/5.函数及作用域/2.函数文档.html">
            
                
                    <a href="../../home/5.函数及作用域/2.函数文档.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        函数文档
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="home/5.函数及作用域/3.变量的作用域.html">
            
                
                    <a href="../../home/5.函数及作用域/3.变量的作用域.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        变量的作用域
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="home/5.函数及作用域/4.内部函数和闭包操作.html">
            
                
                    <a href="../../home/5.函数及作用域/4.内部函数和闭包操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        内部函数和闭包操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="home/5.函数及作用域/5.lambda表达式.html">
            
                
                    <a href="../../home/5.函数及作用域/5.lambda表达式.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        lambda表达式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="home/5.函数及作用域/6.高阶函数.html">
            
                
                    <a href="../../home/5.函数及作用域/6.高阶函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        高阶函数
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" >
            
            <span><b>6.</b> 内置函数及操作</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="home/6.内置函数及操作/1.字符串相关.html">
            
                
                    <a href="../../home/6.内置函数及操作/1.字符串相关.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        字符串相关
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="home/6.内置函数及操作/2.format格式字符串.html">
            
                
                    <a href="../../home/6.内置函数及操作/2.format格式字符串.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        format格式字符串
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="home/6.内置函数及操作/3.内建函数.html">
            
                
                    <a href="../../home/6.内置函数及操作/3.内建函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        内建函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="home/6.内置函数及操作/4.列表.html">
            
                
                    <a href="../../home/6.内置函数及操作/4.列表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        列表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="home/6.内置函数及操作/5.元组.html">
            
                
                    <a href="../../home/6.内置函数及操作/5.元组.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        元组
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="home/6.内置函数及操作/6.字典.html">
            
                
                    <a href="../../home/6.内置函数及操作/6.字典.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        字典
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="home/6.内置函数及操作/7.集合.html">
            
                
                    <a href="../../home/6.内置函数及操作/7.集合.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        集合
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="home/6.内置函数及操作/8.文件操作.html">
            
                
                    <a href="../../home/6.内置函数及操作/8.文件操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        文件操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" >
            
            <span><b>7.</b> 常用的模块</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="home/7.常用模块/1.String模块.html">
            
                
                    <a href="../../home/7.常用模块/1.String模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        String模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="home/7.常用模块/2.math模块.html">
            
                
                    <a href="../../home/7.常用模块/2.math模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        math模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="home/7.常用模块/3.OS模块.html">
            
                
                    <a href="../../home/7.常用模块/3.OS模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        OS模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="home/7.常用模块/4.zipfile模块.html">
            
                
                    <a href="../../home/7.常用模块/4.zipfile模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        zipfile模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="home/7.常用模块/5.tarfile模块.html">
            
                
                    <a href="../../home/7.常用模块/5.tarfile模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        tarfile模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="home/7.常用模块/6.shutil模块.html">
            
                
                    <a href="../../home/7.常用模块/6.shutil模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.6.</b>
                        
                        shutil模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.7" data-path="home/7.常用模块/7.时间相关模块.html">
            
                
                    <a href="../../home/7.常用模块/7.时间相关模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.7.</b>
                        
                        时间相关模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" >
            
            <span><b>8.</b> 面向对象</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="home/8.面向对象/1.类和对象-上.html">
            
                
                    <a href="../../home/8.面向对象/1.类和对象-上.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        类和对象-上
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="home/8.面向对象/2.类和对象-下.html">
            
                
                    <a href="../../home/8.面向对象/2.类和对象-下.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        类和对象-下
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="home/8.面向对象/3.魔术方法.html">
            
                
                    <a href="../../home/8.面向对象/3.魔术方法.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        魔术方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="home/8.面向对象/4.装饰器.html">
            
                
                    <a href="../../home/8.面向对象/4.装饰器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        装饰器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="home/8.面向对象/5.抽象类.html">
            
                
                    <a href="../../home/8.面向对象/5.抽象类.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        抽象类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="home/8.面向对象/6.错误和异常处理.html">
            
                
                    <a href="../../home/8.面向对象/6.错误和异常处理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        错误和异常处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.7" data-path="home/8.面向对象/7.模块和包.html">
            
                
                    <a href="../../home/8.面向对象/7.模块和包.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.7.</b>
                        
                        模块和包
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" >
            
            <span><b>9.</b> tkinter模块</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="9.1" data-path="home/9.tkinter模块/tkinter模块.html">
            
                
                    <a href="../../home/9.tkinter模块/tkinter模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        tkinter模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="home/10.网络编程/1.网络编程.html">
            
                
                    <a href="../../home/10.网络编程/1.网络编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        网络编程
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="10.1" data-path="home/10.网络编程/2.TCP编程.html">
            
                
                    <a href="../../home/10.网络编程/2.TCP编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.1.</b>
                        
                        TCP编程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.2" data-path="home/10.网络编程/3.UDP编程.html">
            
                
                    <a href="../../home/10.网络编程/3.UDP编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.2.</b>
                        
                        UDP编程
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="11" data-path="home/11.多任务/多任务原理.html">
            
                
                    <a href="../../home/11.多任务/多任务原理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        多任务
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="11.1" data-path="home/11.多任务/1.多进程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/1.多进程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.1.</b>
                        
                        多进程实现多任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.2" data-path="home/11.多任务/2.多线程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/2.多线程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.2.</b>
                        
                        多线程实现多任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.3" data-path="home/11.多任务/3.协程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/3.协程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.3.</b>
                        
                        协程实现多任务
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="12" >
            
            <span><b>12.</b> Python实战项目</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.1" data-path="home/12.Python实战项目/1.简易计算器.html">
            
                
                    <a href="../../home/12.Python实战项目/1.简易计算器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.1.</b>
                        
                        简易计算器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.2" data-path="home/12.Python实战项目/2.自动售货机.html">
            
                
                    <a href="../../home/12.Python实战项目/2.自动售货机.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.2.</b>
                        
                        自动售货机
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.3" data-path="home/12.Python实战项目/3.银行项目.html">
            
                
                    <a href="../../home/12.Python实战项目/3.银行项目.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.3.</b>
                        
                        银行项目
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.4" data-path="home/12.Python实战项目/4.简单的登录注册.html">
            
                
                    <a href="../../home/12.Python实战项目/4.简单的登录注册.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.4.</b>
                        
                        简单的登录注册
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.5" data-path="home/12.Python实战项目/5.双色球.html">
            
                
                    <a href="../../home/12.Python实战项目/5.双色球.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.5.</b>
                        
                        双色球
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.6" data-path="home/12.Python实战项目/6.python垃圾回收机制.html">
            
                
                    <a href="../../home/12.Python实战项目/6.python垃圾回收机制.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.6.</b>
                        
                        python垃圾回收机制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.7" data-path="home/12.Python实战项目/7.turtle画国旗.html">
            
                
                    <a href="../../home/12.Python实战项目/7.turtle画国旗.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.7.</b>
                        
                        turtle画国旗
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.8" data-path="home/12.Python实战项目/8.turtle画小猪佩奇.html">
            
                
                    <a href="../../home/12.Python实战项目/8.turtle画小猪佩奇.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.8.</b>
                        
                        turtle画小猪佩奇
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.9" data-path="home/12.Python实战项目/9.turtle画个表.html">
            
                
                    <a href="../../home/12.Python实战项目/9.turtle画个表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.9.</b>
                        
                        turtle画个表
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >MXY 1.0版Python整理</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="tkinter&#x6A21;&#x5757;">tkinter&#x6A21;&#x5757;</h1>
<hr>
<ul>
<li><h3 id="&#x57FA;&#x7840;&#x4EE3;&#x7801;">&#x57FA;&#x7840;&#x4EE3;&#x7801;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  win.mainloop()
</code></pre>
</li>
</ul>
<ul>
<li><h3 id="&#x7B80;&#x5355;&#x793A;&#x4F8B;">&#x7B80;&#x5355;&#x793A;&#x4F8B;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  <span class="hljs-comment"># &#x521B;&#x5EFA;&#x4E3B;&#x7A97;&#x53E3;</span>
  win = tkinter.Tk()
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x6807;&#x9898;</span>
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x5927;&#x5C0F;&#x548C;&#x4F4D;&#x7F6E;</span>
  win.geometry(<span class="hljs-string">&quot;800x600+200+200&quot;</span>)

  <span class="hljs-comment"># &#x8FDB;&#x5165;&#x6D88;&#x606F;&#x5FAA;&#x73AF;</span>
  win.mainloop()
</code></pre>
</li>
<li><h3 id="label&#x63A7;&#x4EF6;">Label&#x63A7;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  <span class="hljs-comment"># &#x521B;&#x5EFA;&#x4E3B;&#x7A97;&#x53E3;</span>
  win = tkinter.Tk()
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x6807;&#x9898;</span>
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x5927;&#x5C0F;&#x548C;&#x4F4D;&#x7F6E;</span>
  win.geometry(<span class="hljs-string">&quot;800x600+200+200&quot;</span>)

  <span class="hljs-string">&quot;&quot;&quot;
  Label&#xFF1A;&#x6807;&#x7B7E;&#x63A7;&#x4EF6;&#xFF0C;&#x53EF;&#x4EE5;&#x663E;&#x793A;&#x6587;&#x672C;
  win           &#x7236;&#x7A97;&#x4F53;
  text          &#x663E;&#x793A;&#x7684;&#x6587;&#x672C;&#x5185;&#x5BB9;
  bg            &#x5B57;&#x4F53;&#x989C;&#x8272;
  width         &#x5BBD;&#x5EA6;
  height        &#x9AD8;&#x5EA6;
  wraplength    &#x6307;&#x5B9A;text&#x6587;&#x672C;&#x4E2D;&#x591A;&#x5BBD;&#x8FDB;&#x884C;&#x6362;&#x884C;
  justify       &#x8BBE;&#x7F6E;&#x6362;&#x884C;&#x540E;&#x7684;&#x5BF9;&#x9F50;&#x65B9;&#x5F0F;
  anchor        &#x4F4D;&#x7F6E;&#xFF1A;n,  ne,  e,  se,   s,  sw,   w,  nw, or center
                  &#x5317;  &#x4E1C;&#x5317;  &#x4E1C;  &#x4E1C;&#x5357;  &#x5357;  &#x897F;&#x5357;  &#x897F;  &#x897F;&#x5317;     &#x5C45;&#x4E2D;
  &quot;&quot;&quot;</span>
  label = tkinter.Label(win,
                      text=<span class="hljs-string">&quot;&#x9AD8;&#x60E0;&#x6587;&#x666F;&#x6B66;&#x662D;&#x5BA3;&quot;</span>,
                      bg=<span class="hljs-string">&apos;#FF7259&apos;</span>,
                      fg=<span class="hljs-string">&quot;#FFFFFF&quot;</span>,
                      font=(<span class="hljs-string">&quot;&#x5FAE;&#x8F6F;&#x96C5;&#x9ED1;&quot;</span>, <span class="hljs-number">20</span>),
                      width=<span class="hljs-number">20</span>,
                      height=<span class="hljs-number">10</span>,
                      wraplength=<span class="hljs-number">50</span>,
                      justify=<span class="hljs-string">&quot;left&quot;</span>,
                      anchor=<span class="hljs-string">&quot;center&quot;</span>
                      )
  <span class="hljs-comment"># &#x663E;&#x793A;&#x51FA;&#x6765;</span>
  label.pack()
  win.mainloop()
</code></pre>
</li>
<li><h3 id="button&#x63A7;&#x4EF6;">Button&#x63A7;&#x4EF6;</h3>
<p>  ```py</p>
<h1 id="codingutf8-">-<em>- coding:utf-8 -</em>-</h1>
<p>  import tkinter</p>
<p>  def func():</p>
<pre><code>  print(&quot;meng is a good man&quot;)
</code></pre></li>
</ul>
<pre><code># &#x521B;&#x5EFA;&#x4E3B;&#x7A97;&#x53E3;
win = tkinter.Tk()
# &#x8BBE;&#x7F6E;&#x6807;&#x9898;
win.title(&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;)
# &#x8BBE;&#x7F6E;&#x5927;&#x5C0F;&#x548C;&#x4F4D;&#x7F6E;
win.geometry(&quot;800x600+200+200&quot;)

# &#x521B;&#x5EFA;&#x6309;&#x94AE;
button1 = tkinter.Button(win,
                        text=&quot;&#x4E00;&#x5929;&#x4E09;&#x987F;&#x5C0F;&#x70E7;&#x70E4;&quot;,
                        command=func,
                        width=15,
                        height=2,)
button1.pack()

button2 = tkinter.Button(win,
                        text=&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;,
                        command=lambda: print(&apos;meng is a nice man&apos;),
                        width=15,
                        height=2,)
button2.pack()

button3 = tkinter.Button(win,
                        text=&quot;&#x9000;&#x51FA;&quot;,
                        command=win.quit,
                        width=15,
                        height=2, )
button3.pack()


win.mainloop()
```
</code></pre><ul>
<li><h3 id="entry&#x63A7;&#x4EF6;">Entry&#x63A7;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  <span class="hljs-comment"># &#x521B;&#x5EFA;&#x4E3B;&#x7A97;&#x53E3;</span>
  win = tkinter.Tk()
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x6807;&#x9898;</span>
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x5927;&#x5C0F;&#x548C;&#x4F4D;&#x7F6E;</span>
  win.geometry(<span class="hljs-string">&quot;800x600+200+200&quot;</span>)

  <span class="hljs-string">&quot;&quot;&quot;
  &#x8F93;&#x5165;&#x63A7;&#x4EF6;
  &#x7528;&#x4E8E;&#x663E;&#x793A;&#x7B80;&#x5355;&#x7684;&#x6587;&#x672C;&#x5185;&#x5BB9;
  show&#xFF1A;show=&quot;*&quot;        &#x5BC6;&#x6587;&#x663E;&#x793A;

  &quot;&quot;&quot;</span>
  <span class="hljs-comment"># &#x7ED1;&#x5B9A;&#x53D8;&#x91CF;</span>
  e = tkinter.Variable()

  entry = tkinter.Entry(win,
                      <span class="hljs-comment"># show=&quot;*&quot;</span>
                      textvariable=e,
                      width=<span class="hljs-number">30</span>,

                      )
  entry.pack()
  <span class="hljs-comment"># e&#x5C31;&#x4EE3;&#x8868;&#x8F93;&#x5165;&#x6846;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;</span>
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x503C;</span>
  e.set(<span class="hljs-string">&quot;meng is a nice man&quot;</span>)
  <span class="hljs-comment"># &#x53D6;&#x503C;</span>
  print(e.get())
  print(entry.get())

  win.mainloop()
</code></pre>
</li>
</ul>
<ul>
<li><h3 id="&#x70B9;&#x51FB;&#x6309;&#x94AE;&#x8F93;&#x51FA;&#x8F93;&#x5165;&#x6846;&#x4E2D;&#x7684;&#x5185;&#x5BB9;">&#x70B9;&#x51FB;&#x6309;&#x94AE;&#x8F93;&#x51FA;&#x8F93;&#x5165;&#x6846;&#x4E2D;&#x7684;&#x5185;&#x5BB9;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  <span class="hljs-comment"># &#x521B;&#x5EFA;&#x4E3B;&#x7A97;&#x53E3;</span>
  win = tkinter.Tk()
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x6807;&#x9898;</span>
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x5927;&#x5C0F;&#x548C;&#x4F4D;&#x7F6E;</span>
  win.geometry(<span class="hljs-string">&quot;800x600+200+200&quot;</span>)

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">showInfo</span><span class="hljs-params">()</span>:</span>
      print(entry.get())

  entry = tkinter.Entry(win)
  entry.pack()

  button = tkinter.Button(win, text=<span class="hljs-string">&quot;&#x6309;&#x94AE;&quot;</span>, command=showInfo)
  button.pack()

  win.mainloop()
</code></pre>
</li>
</ul>
<ul>
<li><h3 id="text&#x63A7;&#x4EF6;">Text&#x63A7;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  <span class="hljs-comment"># &#x521B;&#x5EFA;&#x4E3B;&#x7A97;&#x53E3;</span>
  win = tkinter.Tk()
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x6807;&#x9898;</span>
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x5927;&#x5C0F;&#x548C;&#x4F4D;&#x7F6E;</span>
  win.geometry(<span class="hljs-string">&quot;800x600+200+200&quot;</span>)

  <span class="hljs-string">&quot;&quot;&quot;
  &#x6587;&#x672C;&#x63A7;&#x4EF6;&#xFF0C;&#x7528;&#x4E8E;&#x663E;&#x793A;&#x591A;&#x884C;&#x6587;&#x672C;
  # height        &#x663E;&#x793A;&#x7684;&#x884C;&#x6570;
  &quot;&quot;&quot;</span>
  text = tkinter.Text(win,
                      width=<span class="hljs-number">30</span>,
                      height=<span class="hljs-number">10</span>,
                      font=(<span class="hljs-string">&quot;&#x5FAE;&#x8F6F;&#x96C5;&#x9ED1;&quot;</span>, <span class="hljs-number">15</span>),
                      )
  text.pack()
  str = <span class="hljs-string">&apos;jio hdasi ohdas oihosi hfasoih oidoias hoish aoh isod hoiashd oihoih asdh osaihd oasih sd sdzc sad zxc sad hashdga jszh chzxkjn kjashd acxzncjkjk c xbx sz asjbiasb jkzxb bsa buiabcxzbc zxh chxzbc uzv ciabs uvdsoXZB&apos;</span>
  text.insert(tkinter.INSERT, str)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="&#x5E26;&#x6EDA;&#x52A8;&#x6761;&#x7684;text">&#x5E26;&#x6EDA;&#x52A8;&#x6761;&#x7684;text</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  <span class="hljs-comment"># &#x521B;&#x5EFA;&#x4E3B;&#x7A97;&#x53E3;</span>
  win = tkinter.Tk()
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x6807;&#x9898;</span>
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x5927;&#x5C0F;&#x548C;&#x4F4D;&#x7F6E;</span>
  <span class="hljs-comment"># win.geometry(&quot;800x600+200+200&quot;)</span>

  <span class="hljs-string">&quot;&quot;&quot;
  &#x6587;&#x672C;&#x63A7;&#x4EF6;&#xFF0C;&#x7528;&#x4E8E;&#x663E;&#x793A;&#x591A;&#x884C;&#x6587;&#x672C;
  # height        &#x663E;&#x793A;&#x7684;&#x884C;&#x6570;
  &quot;&quot;&quot;</span>
  <span class="hljs-comment"># &#x521B;&#x5EFA;&#x6EDA;&#x52A8;&#x6761;</span>
  scroll = tkinter.Scrollbar()

  text = tkinter.Text(win,
                      width=<span class="hljs-number">30</span>,
                      height=<span class="hljs-number">8</span>,
                      font=(<span class="hljs-string">&quot;&#x5FAE;&#x8F6F;&#x96C5;&#x9ED1;&quot;</span>, <span class="hljs-number">15</span>),)
  <span class="hljs-comment"># side&#x653E;&#x5230;&#x7A97;&#x4F53;&#x7684;&#x54EA;&#x4E00;&#x4FA7;  fill&#x586B;&#x5145;</span>
  scroll.pack(side=tkinter.RIGHT, fill=tkinter.Y)
  text.pack(side=tkinter.LEFT, fill=tkinter.Y)
  <span class="hljs-comment"># &#x5173;&#x8054;</span>
  scroll.config(command=text.yview)
  text.config(yscrollcommand=scroll.set)

  str = <span class="hljs-string">&apos;jio hdasi ohdas oihosi hfasoih oidoias hoish aoh isod hoiashd oihoih asdh osaihd oasih sd sdzc sad zxc sad hashdga jszh chzxkjn kjashd acxzncjkjk c xbx sz asjbiasb jkzxb bsa buiabcxzbc zxh chxzbc uzv ciabs uvdsoXZB sdsajkk asch jkoiaa u nxci nudd niu uxci oxcn uxc ncxon xco noxcn lkcxn cnx lnxc nzlknzx bihpz aigcui oixosnoi oi nxzoi xz[oi pxzi o[ixzho[xi [oizxh [oixzo[ixzho [hxz[oih ioxzh jxz jk czx cohzxoc ha c z;xn ckjzxcjasb cjbxvjxcl kvbkjs;h sn njvbnvosn u[baiosoif sjd[oifh [asohucv [von a[jdgnao i jkcvn jna diufbuoabi[os ofdo hvn jkxnpbibiu jxnv jcnvijbx[uzf haso hgaodfhg oiahg adfhg fdahg u[fdahg uadhg uafhdg ufdh&apos;</span>
  text.insert(tkinter.INSERT, str)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="checkbutton&#x591A;&#x9009;&#x6846;&#x63A7;&#x4EF6;">CheckButton&#x591A;&#x9009;&#x6846;&#x63A7;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;800x600+200+200&quot;</span>)

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">update</span><span class="hljs-params">()</span>:</span>
      message = <span class="hljs-string">&quot;&quot;</span>
      <span class="hljs-keyword">if</span> hobby1.get() == <span class="hljs-keyword">True</span>:
          message += <span class="hljs-string">&quot;money\n&quot;</span>
      <span class="hljs-keyword">if</span> hobby2.get() == <span class="hljs-keyword">True</span>:
          message += <span class="hljs-string">&quot;power\n&quot;</span>
      <span class="hljs-keyword">if</span> hobby3.get() == <span class="hljs-keyword">True</span>:
          message += <span class="hljs-string">&quot;people\n&quot;</span>
      <span class="hljs-comment"># &#x6E05;&#x9664;text&#x4E2D;&#x7684;&#x6240;&#x6709;&#x5185;&#x5BB9;</span>
      text.delete(<span class="hljs-number">0.0</span>, tkinter.END)
      text.insert(tkinter.INSERT, message)

  <span class="hljs-comment"># &#x8981;&#x7ED1;&#x5B9A;&#x7684;&#x53D8;&#x91CF;</span>
  hobby1 = tkinter.BooleanVar()
  check1 = tkinter.Checkbutton(win,
                              text=<span class="hljs-string">&quot;money&quot;</span>,
                              variable=hobby1,
                              command=update,)
  check1.pack()
  hobby2 = tkinter.BooleanVar()
  check2 = tkinter.Checkbutton(win,
                              text=<span class="hljs-string">&quot;power&quot;</span>,
                              variable=hobby2,
                              command=update,
                              )
  check2.pack()
  hobby3 = tkinter.BooleanVar()
  check3 = tkinter.Checkbutton(win,
                              text=<span class="hljs-string">&quot;people&quot;</span>,
                              variable=hobby3,
                              command=update,
                              )
  check3.pack()

  text = tkinter.Text(win, width=<span class="hljs-number">50</span>, height=<span class="hljs-number">5</span>)
  text.pack()

  win.mainloop()
</code></pre>
</li>
<li><h3 id="radiobutton&#x5355;&#x9009;&#x6846;&#x63A7;&#x4EF6;">Radiobutton&#x5355;&#x9009;&#x6846;&#x63A7;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;800x600+200+200&quot;</span>)

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">update</span><span class="hljs-params">()</span>:</span>
      print(r.get())

  <span class="hljs-comment"># &#x4E00;&#x7EC4;&#x5355;&#x9009;&#x6846;&#x8981;&#x7ED1;&#x5B9A;&#x540C;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;</span>
  r = tkinter.IntVar()
  radio1 = tkinter.Radiobutton(win, text=<span class="hljs-string">&quot;one&quot;</span>, value=<span class="hljs-number">1</span>, variable=r, command=update)
  radio1.pack()
  radio2 = tkinter.Radiobutton(win, text=<span class="hljs-string">&quot;tow&quot;</span>, value=<span class="hljs-number">2</span>, variable=r, command=update)
  radio2.pack()

  win.mainloop()
</code></pre>
</li>
<li><h3 id="listbox&#x63A7;&#x4EF6;">Listbox&#x63A7;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;800x600+200+200&quot;</span>)

  <span class="hljs-string">&quot;&quot;&quot;
  &#x5217;&#x8868;&#x6846;&#x63A7;&#x4EF6;&#xFF0C;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x4E00;&#x4E2A;&#x6216;&#x8005;&#x591A;&#x4E2A;&#x6587;&#x672C;&#x6846;
  &#x4F5C;&#x7528;&#xFF1A;&#x5728;listbox&#x63A7;&#x4EF6;&#x7684;&#x5C0F;&#x7A97;&#x53E3;&#x663E;&#x793A;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;
  &quot;&quot;&quot;</span>
  <span class="hljs-comment"># 1&#x3001;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;listbox&#xFF0C;&#x6DFB;&#x52A0;&#x51E0;&#x4E2A;&#x5143;&#x7D20;</span>
  lb = tkinter.Listbox(win, selectmode=tkinter.BROWSE)
  lb.pack()

  <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;good&quot;</span>, <span class="hljs-string">&quot;nice&quot;</span>, <span class="hljs-string">&quot;handsome&quot;</span>, <span class="hljs-string">&quot;vg&quot;</span>, <span class="hljs-string">&quot;vn&quot;</span>]:
      <span class="hljs-comment"># &#x6309;&#x987A;&#x5E8F;&#x6DFB;&#x52A0;</span>
      lb.insert(tkinter.END, item)
  <span class="hljs-comment"># &#x5728;&#x5F00;&#x59CB;&#x6DFB;&#x52A0;</span>
  lb.insert(tkinter.ACTIVE, <span class="hljs-string">&quot;cool&quot;</span>)
  <span class="hljs-comment"># &#x5C06;&#x5217;&#x8868;&#x5F53;&#x6210;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x6DFB;&#x52A0;&#x7684;</span>
  <span class="hljs-comment"># lb.insert(tkinter.END, [&quot;very good&quot;, &quot;very nice&quot;])</span>

  <span class="hljs-comment"># &#x5220;&#x9664;&#xFF0C;&#x53C2;&#x6570;1&#x4E3A;&#x5F00;&#x59CB;&#x7684;&#x7D22;&#x5F15;,&#x53C2;&#x6570;2&#x4F4D;&#x7ED3;&#x675F;&#x7684;&#x7D22;&#x5F15;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x6307;&#x5B9A;&#x53C2;&#x6570;2&#xFF0C;&#x53EA;&#x5220;&#x9664;&#x7B2C;&#x4E00;&#x4E2A;&#x7D22;&#x5F15;&#x5904;&#x7684;&#x5185;&#x5BB9;</span>
  <span class="hljs-comment"># lb.delete(1, 3)</span>
  <span class="hljs-comment"># lb.delete(1)</span>

  <span class="hljs-comment"># &#x9009;&#x4E2D;&#xFF0C;&#x53C2;&#x6570;1&#x4E3A;&#x5F00;&#x59CB;&#x7684;&#x7D22;&#x5F15;,&#x53C2;&#x6570;2&#x4F4D;&#x7ED3;&#x675F;&#x7684;&#x7D22;&#x5F15;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x6307;&#x5B9A;&#x53C2;&#x6570;2&#xFF0C;&#x53EA;&#x9009;&#x4E2D;&#x7B2C;&#x4E00;&#x4E2A;&#x7D22;&#x5F15;&#x5904;&#x7684;&#x5185;&#x5BB9;</span>
  lb.select_set(<span class="hljs-number">2</span>, <span class="hljs-number">5</span>)
  <span class="hljs-comment"># lb.select_set(2)</span>
  <span class="hljs-comment"># &#x53D6;&#x6D88;&#x9009;&#x4E2D;</span>
  <span class="hljs-comment"># lb.select_clear(2, 4)</span>
  <span class="hljs-comment"># lb.select_clear(3)</span>

  <span class="hljs-comment"># &#x83B7;&#x53D6;&#x5230;&#x5217;&#x8868;&#x4E2D;&#x5143;&#x7D20;&#x7684;&#x4E2A;&#x6570;</span>
  <span class="hljs-comment"># print(lb.size())</span>
  <span class="hljs-comment"># &#x4ECE;&#x5217;&#x8868;&#x4E2D;&#x53D6;&#x503C;&#xFF0C;&#x53C2;&#x6570;1&#x4E3A;&#x5F00;&#x59CB;&#x7684;&#x7D22;&#x5F15;,&#x53C2;&#x6570;2&#x4F4D;&#x7ED3;&#x675F;&#x7684;&#x7D22;&#x5F15;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x6307;&#x5B9A;&#x53C2;&#x6570;2&#xFF0C;&#x53EA;&#x5220;&#x9664;&#x7B2C;&#x4E00;&#x4E2A;&#x7D22;&#x5F15;&#x5904;&#x7684;&#x5185;&#x5BB9;</span>
  <span class="hljs-comment"># print(lb.get(2, 4))</span>
  <span class="hljs-comment"># print(lb.get(2))</span>

  <span class="hljs-comment"># &#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x9009;&#x4E2D;&#x5143;&#x7D20;&#x7684;&#x7D22;&#x5F15;&#x9879;&#xFF0C;&#x4E0D;&#x662F;item&#x5143;&#x7D20;</span>
  print(lb.curselection())

  <span class="hljs-comment"># &#x5224;&#x65AD;&#x4E00;&#x4E2A;&#x9009;&#x9879;&#x662F;&#x5426;&#x88AB;&#x9009;&#x4E2D;</span>
  print(lb.selection_includes(<span class="hljs-number">1</span>))
  print(lb.selection_includes(<span class="hljs-number">3</span>))

  win.mainloop()
</code></pre>
</li>
<li><h3 id="listbox&#x63A7;&#x4EF6;&#x4E2D;">Listbox&#x63A7;&#x4EF6;(&#x4E2D;)</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;800x600+200+200&quot;</span>)

  <span class="hljs-comment"># &#x7ED1;&#x5B9A;&#x53D8;&#x91CF;</span>
  lbv = tkinter.StringVar()

  <span class="hljs-comment"># &#x4E8E;BROWSE&#x76F8;&#x4F3C;&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x652F;&#x6301;&#x9F20;&#x6807;&#x6309;&#x4E0B;&#x540E;&#x79FB;&#x52A8;&#x9009;&#x4E2D;&#x4F4D;&#x7F6E;</span>
  lb = tkinter.Listbox(win, selectmode=tkinter.SINGLE, listvariable=lbv)
  lb.pack()

  <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;good&quot;</span>, <span class="hljs-string">&quot;nice&quot;</span>, <span class="hljs-string">&quot;handsome&quot;</span>, <span class="hljs-string">&quot;vg&quot;</span>, <span class="hljs-string">&quot;vn&quot;</span>]:
      <span class="hljs-comment"># &#x6309;&#x987A;&#x5E8F;&#x6DFB;&#x52A0;</span>
      lb.insert(tkinter.END, item)
  <span class="hljs-comment"># &#x5728;&#x5F00;&#x59CB;&#x6DFB;&#x52A0;</span>
  lb.insert(tkinter.ACTIVE, <span class="hljs-string">&quot;cool&quot;</span>)

  <span class="hljs-comment"># &#x6253;&#x5370;&#x5F53;&#x524D;&#x5217;&#x8868;&#x4E2D;&#x7684;&#x9009;&#x9879;</span>
  print(lbv.get())

  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x9009;&#x9879;</span>
  <span class="hljs-comment"># lbv.set((&quot;1&quot;, &quot;2&quot;, &quot;3&quot;))</span>

  <span class="hljs-comment"># &#x7ED1;&#x5B9A;&#x4E8B;&#x4EF6;</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">myPrint</span><span class="hljs-params">(event)</span>:</span>
      print(lb.get(lb.curselection()))
  lb.bind(<span class="hljs-string">&quot;&lt;Double-Button-1&gt;&quot;</span>, myPrint)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="listbox&#x63A7;&#x4EF6;&#x4E2D;&#x4E0B;">Listbox&#x63A7;&#x4EF6;(&#x4E2D;&#x4E0B;)</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  <span class="hljs-comment"># win.geometry(&quot;800x600+200+200&quot;)</span>

  <span class="hljs-comment"># EXTENDED&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;listbox&#x652F;&#x6301;shift&#x548C;control</span>
  lb = tkinter.Listbox(win, selectmode=tkinter.EXTENDED)

  <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;good&quot;</span>, <span class="hljs-string">&quot;nice&quot;</span>, <span class="hljs-string">&quot;handsome&quot;</span>, <span class="hljs-string">&quot;vg&quot;</span>, <span class="hljs-string">&quot;vn&quot;</span>, <span class="hljs-string">&quot;good1&quot;</span>, <span class="hljs-string">&quot;nice1&quot;</span>, <span class="hljs-string">&quot;handsome1&quot;</span>, <span class="hljs-string">&quot;vg1&quot;</span>, <span class="hljs-string">&quot;vn1&quot;</span>, <span class="hljs-string">&quot;good2&quot;</span>, <span class="hljs-string">&quot;nice2&quot;</span>, <span class="hljs-string">&quot;handsome2&quot;</span>, <span class="hljs-string">&quot;vg2&quot;</span>, <span class="hljs-string">&quot;vn2&quot;</span>]:
      <span class="hljs-comment"># &#x6309;&#x987A;&#x5E8F;&#x6DFB;&#x52A0;</span>
      lb.insert(tkinter.END, item)

  <span class="hljs-comment"># &#x6309;&#x4F4F;shift&#xFF0C;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x8FDE;&#x9009;</span>
  <span class="hljs-comment"># &#x6309;&#x4F4F;control&#xFF0C;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x591A;&#x9009;</span>

  <span class="hljs-comment"># &#x6EDA;&#x52A8;&#x6761;</span>
  sc = tkinter.Scrollbar(win)
  sc.pack(side=tkinter.RIGHT, fill=tkinter.Y)
  lb.configure(yscrollcommand=sc.set)
  lb.pack(side=tkinter.LEFT, fill=tkinter.BOTH)
  sc[<span class="hljs-string">&apos;command&apos;</span>] = lb.yview

  win.mainloop()
</code></pre>
</li>
<li><h3 id="listbox&#x63A7;&#x4EF6;&#x4E0B;">Listbox&#x63A7;&#x4EF6;(&#x4E0B;)</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;800x600+200+200&quot;</span>)

  <span class="hljs-comment"># MULTIPLE&#xFF0C;&#x652F;&#x6301;&#x591A;&#x9009;</span>
  lb = tkinter.Listbox(win, selectmode=tkinter.MULTIPLE)
  lb.pack()
  <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;good&quot;</span>, <span class="hljs-string">&quot;nice&quot;</span>, <span class="hljs-string">&quot;handsome&quot;</span>, <span class="hljs-string">&quot;vg&quot;</span>, <span class="hljs-string">&quot;vn&quot;</span>, <span class="hljs-string">&quot;good1&quot;</span>, <span class="hljs-string">&quot;nice1&quot;</span>, <span class="hljs-string">&quot;handsome1&quot;</span>, <span class="hljs-string">&quot;vg1&quot;</span>, <span class="hljs-string">&quot;vn1&quot;</span>, <span class="hljs-string">&quot;good2&quot;</span>, <span class="hljs-string">&quot;nice2&quot;</span>, <span class="hljs-string">&quot;handsome2&quot;</span>, <span class="hljs-string">&quot;vg2&quot;</span>, <span class="hljs-string">&quot;vn2&quot;</span>]:
      <span class="hljs-comment"># &#x6309;&#x987A;&#x5E8F;&#x6DFB;&#x52A0;</span>
      lb.insert(tkinter.END, item)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="scale&#x63A7;&#x4EF6;">Scale&#x63A7;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;800x600+200+200&quot;</span>)

  <span class="hljs-string">&quot;&quot;&quot;
  &#x4F9B;&#x7528;&#x6237;&#x901A;&#x8FC7;&#x62D6;&#x62FD;&#x6307;&#x793A;&#x5668;&#x6539;&#x53D8;&#x53D8;&#x91CF;&#x7684;&#x503C;&#xFF0C;&#x53EF;&#x4EE5;&#x6C34;&#x5E73;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x7AD6;&#x76F4;
  tkinter.HORIZONTAL      &#x6C34;&#x5E73;
  tkinter.VERTICAL        &#x7AD6;&#x76F4;
  length                  &#x6C34;&#x5E73;&#x65F6;&#x8868;&#x793A;&#x5BBD;&#x5EA6;&#xFF0C;&#x7AD6;&#x76F4;&#x65F6;&#x8868;&#x793A;&#x9AD8;&#x5EA6;
  tickinterval            &#x9009;&#x62E9;&#x503C;&#x5C06;&#x4F1A;&#x4E3A;&#x8BE5;&#x503C;&#x7684;&#x500D;&#x6570;

  &quot;&quot;&quot;</span>

  scale = tkinter.Scale(win, from_=<span class="hljs-number">0</span>, to=<span class="hljs-number">100</span>, orient=tkinter.HORIZONTAL, tickinterval=<span class="hljs-number">10</span>, length=<span class="hljs-number">400</span>)
  scale.pack()

  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x503C;</span>
  scale.set(<span class="hljs-number">20</span>)

  <span class="hljs-comment"># &#x53D6;&#x503C;</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">showNum</span><span class="hljs-params">()</span>:</span>
      print(scale.get())

  tkinter.Button(win, text=<span class="hljs-string">&quot;&#x6309;&#x94AE;&quot;</span>, command=showNum).pack()

  win.mainloop()
</code></pre>
</li>
<li><h3 id="spinbox&#x63A7;&#x4EF6;">Spinbox&#x63A7;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;800x600+200+200&quot;</span>)

  <span class="hljs-string">&quot;&quot;&quot;
  &#x6570;&#x503C;&#x8303;&#x56F4;&#x63A7;&#x4EF6;
  increment       &#x6B65;&#x957F;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;1
  values          &#x6700;&#x597D;&#x4E0D;&#x8981;&#x4E0E;from_=0, to=100, increment=2&#x540C;&#x65F6;&#x4F7F;&#x7528;
  &quot;&quot;&quot;</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">update</span><span class="hljs-params">()</span>:</span>
      print(v.get())

  <span class="hljs-comment"># &#x7ED1;&#x5B9A;&#x4E2A;&#x53D8;&#x91CF;</span>
  v = tkinter.StringVar()

  <span class="hljs-comment"># sp = tkinter.Spinbox(win, value=(0, 2, 4, 6, 8))</span>
  <span class="hljs-comment"># command       &#x53EA;&#x8981;&#x503C;&#x6539;&#x53D8;&#x5C31;&#x4F1A;&#x6267;&#x884C;&#x5BF9;&#x5E94;&#x7684;&#x65B9;&#x6CD5;</span>
  sp = tkinter.Spinbox(win, from_=<span class="hljs-number">0</span>, to=<span class="hljs-number">100</span>, increment=<span class="hljs-number">2</span>, textvariable=v, command=update)
  sp.pack()

  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x503C;</span>
  v.set(<span class="hljs-number">20</span>)
  <span class="hljs-comment"># &#x53D6;&#x503C;</span>
  print(v.get())

  win.mainloop()
</code></pre>
</li>
<li><h3 id="menu&#x9876;&#x5C42;&#x83DC;&#x5355;">Menu&#x9876;&#x5C42;&#x83DC;&#x5355;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  <span class="hljs-comment"># &#x83DC;&#x5355;&#x6761;</span>
  menubar = tkinter.Menu(win)
  win.config(menu=menubar)

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span><span class="hljs-params">()</span>:</span>
      print(<span class="hljs-string">&quot;meng is a nice man&quot;</span>)

  <span class="hljs-comment"># &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x83DC;&#x5355;&#x9009;&#x9879;</span>
  menu1 = tkinter.Menu(menubar, tearoff=<span class="hljs-keyword">False</span>)
  <span class="hljs-comment"># &#x7ED9;&#x83DC;&#x5355;&#x9009;&#x9879;&#x6DFB;&#x52A0;&#x5185;&#x5BB9;</span>
  <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;Python&quot;</span>, <span class="hljs-string">&quot;C&quot;</span>, <span class="hljs-string">&quot;C++&quot;</span>, <span class="hljs-string">&quot;OC&quot;</span>, <span class="hljs-string">&quot;Swift&quot;</span>, <span class="hljs-string">&quot;C#&quot;</span>, <span class="hljs-string">&quot;shell&quot;</span>, <span class="hljs-string">&quot;Java&quot;</span>, <span class="hljs-string">&quot;JS&quot;</span>, <span class="hljs-string">&quot;PHP&quot;</span>, <span class="hljs-string">&quot;&#x6C47;&#x7F16;&quot;</span>, <span class="hljs-string">&quot;NodeJS&quot;</span>, <span class="hljs-string">&quot;&#x9000;&#x51FA;&quot;</span>]:
      <span class="hljs-keyword">if</span> item == <span class="hljs-string">&quot;&#x9000;&#x51FA;&quot;</span>:
          <span class="hljs-comment"># &#x6DFB;&#x52A0;&#x5206;&#x9694;&#x7EBF;</span>
          menu1.add_separator()
          menu1.add_command(label=item, command=win.quit)
      <span class="hljs-keyword">else</span>:
          menu1.add_command(label=item, command=func)

  <span class="hljs-comment"># &#x5411;&#x83DC;&#x5355;&#x6761;&#x4E0A;&#x6DFB;&#x52A0;&#x83DC;&#x5355;&#x9009;&#x9879;</span>
  menubar.add_cascade(label=<span class="hljs-string">&quot;&#x8BED;&#x8A00;&quot;</span>, menu=menu1)

  menu2 = tkinter.Menu(menubar, tearoff=<span class="hljs-keyword">False</span>)
  menu2.add_command(label=<span class="hljs-string">&quot;red&quot;</span>)
  menu2.add_command(label=<span class="hljs-string">&quot;blue&quot;</span>)
  menubar.add_cascade(label=<span class="hljs-string">&quot;&#x989C;&#x8272;&quot;</span>, menu=menu2)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="menu&#x9F20;&#x6807;&#x53F3;&#x952E;&#x83DC;&#x5355;">Menu&#x9F20;&#x6807;&#x53F3;&#x952E;&#x83DC;&#x5355;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;800x600+200+200&quot;</span>)

  <span class="hljs-comment"># &#x83DC;&#x5355;&#x6761;</span>
  menubar = tkinter.Menu(win)

  <span class="hljs-comment"># &#x83DC;&#x5355;</span>
  menu1 = tkinter.Menu(menubar, tearoff=<span class="hljs-keyword">False</span>)
  <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;Python&quot;</span>, <span class="hljs-string">&quot;C&quot;</span>, <span class="hljs-string">&quot;C++&quot;</span>, <span class="hljs-string">&quot;OC&quot;</span>, <span class="hljs-string">&quot;Swift&quot;</span>, <span class="hljs-string">&quot;C#&quot;</span>, <span class="hljs-string">&quot;shell&quot;</span>, <span class="hljs-string">&quot;Java&quot;</span>, <span class="hljs-string">&quot;JS&quot;</span>, <span class="hljs-string">&quot;PHP&quot;</span>, <span class="hljs-string">&quot;&#x6C47;&#x7F16;&quot;</span>, <span class="hljs-string">&quot;NodeJS&quot;</span>, <span class="hljs-string">&quot;&#x9000;&#x51FA;&quot;</span>]:
      menu1.add_command(label=item)

  menubar.add_cascade(label=<span class="hljs-string">&quot;&#x8BED;&#x8A00;&quot;</span>, menu=menu1)

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">showMenu</span><span class="hljs-params">(event)</span>:</span>
      menubar.post(event.x_root, event.y_root )

  win.bind(<span class="hljs-string">&quot;&lt;Button-3&gt;&quot;</span>, showMenu)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="combobox&#x4E0B;&#x62C9;&#x63A7;&#x4EF6;">Combobox&#x4E0B;&#x62C9;&#x63A7;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter
  <span class="hljs-keyword">from</span> tkinter <span class="hljs-keyword">import</span> ttk

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  <span class="hljs-comment"># &#x7ED1;&#x5B9A;&#x53D8;&#x91CF;</span>
  cv = tkinter.StringVar()
  com = ttk.Combobox(win, textvariable=cv)
  com.pack()
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x4E0B;&#x62C9;&#x6570;&#x636E;</span>
  com[<span class="hljs-string">&quot;value&quot;</span>] = (<span class="hljs-string">&quot;&#x9ED1;&#x9F99;&#x6C5F;&quot;</span>, <span class="hljs-string">&quot;&#x5409;&#x6797;&quot;</span>, <span class="hljs-string">&quot;&#x8FBD;&#x5B81;&quot;</span>)

  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x6839;&#x636E;&#x5143;&#x7EC4;&#x7D22;&#x5F15;&#x6765;&#x8BBE;&#x7F6E;</span>
  com.current(<span class="hljs-number">0</span>)

  <span class="hljs-comment"># &#x7ED1;&#x5B9A;&#x4E8B;&#x4EF6;</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span><span class="hljs-params">(event)</span>:</span>
      print(com.get())
      print(cv.get())
      print(<span class="hljs-string">&quot;meng is a nice man&quot;</span>)

  com.bind(<span class="hljs-string">&quot;&lt;&lt;ComboboxSelected&gt;&gt;&quot;</span>, func)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="frame&#x63A7;&#x4EF6;">Frame&#x63A7;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  <span class="hljs-string">&quot;&quot;&quot;
  &#x6846;&#x67B6;&#x63A7;&#x4EF6;
  &#x5728;&#x5C4F;&#x5E55;&#x4E0A;&#x663E;&#x793A;&#x4E00;&#x4E2A;&#x77E9;&#x5F62;&#x533A;&#x57DF;&#xFF0C;&#x591A;&#x4F5C;&#x4E3A;&#x5BB9;&#x5668;&#x63A7;&#x4EF6;
  &quot;&quot;&quot;</span>

  frm = tkinter.Frame(win)
  frm.pack()

  <span class="hljs-comment"># left</span>
  frm_l = tkinter.Frame(win)
  tkinter.Label(frm_l, text=<span class="hljs-string">&quot;&#x5DE6;&#x4E0A;&quot;</span>, bg=<span class="hljs-string">&quot;#FF7259&quot;</span>, font=(<span class="hljs-string">&quot;&#x5FAE;&#x8F6F;&#x96C5;&#x9ED1;&quot;</span>, <span class="hljs-number">20</span>)).pack(side=tkinter.TOP)
  tkinter.Label(frm_l, text=<span class="hljs-string">&quot;&#x5DE6;&#x4E0B;&quot;</span>, bg=<span class="hljs-string">&quot;#ADB0B6&quot;</span>, font=(<span class="hljs-string">&quot;&#x5FAE;&#x8F6F;&#x96C5;&#x9ED1;&quot;</span>, <span class="hljs-number">20</span>)).pack(side=tkinter.TOP)
  frm_l.pack(side=tkinter.LEFT)
  <span class="hljs-comment"># right</span>
  frm_r = tkinter.Frame(win)
  tkinter.Label(frm_r, text=<span class="hljs-string">&quot;&#x53F3;&#x4E0A;&quot;</span>, bg=<span class="hljs-string">&quot;#37ACA6&quot;</span>, font=(<span class="hljs-string">&quot;&#x5FAE;&#x8F6F;&#x96C5;&#x9ED1;&quot;</span>, <span class="hljs-number">20</span>)).pack(side=tkinter.TOP)
  tkinter.Label(frm_r, text=<span class="hljs-string">&quot;&#x53F3;&#x4E0B;&quot;</span>, bg=<span class="hljs-string">&quot;#EB5350&quot;</span>, font=(<span class="hljs-string">&quot;&#x5FAE;&#x8F6F;&#x96C5;&#x9ED1;&quot;</span>, <span class="hljs-number">20</span>)).pack(side=tkinter.TOP)
  frm_r.pack(side=tkinter.RIGHT)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="&#x8868;&#x683C;&#x6570;&#x636E;">&#x8868;&#x683C;&#x6570;&#x636E;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter
  <span class="hljs-keyword">from</span> tkinter <span class="hljs-keyword">import</span> ttk

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;600x400+200+200&quot;</span>)

  <span class="hljs-comment"># &#x8868;&#x683C;</span>
  tree = ttk.Treeview(win)
  tree.pack()
  <span class="hljs-comment"># &#x5B9A;&#x4E49;&#x5217;</span>
  tree[<span class="hljs-string">&quot;columns&quot;</span>] = (<span class="hljs-string">&quot;&#x59D3;&#x540D;&quot;</span>, <span class="hljs-string">&quot;&#x5E74;&#x9F84;&quot;</span>, <span class="hljs-string">&quot;&#x8EAB;&#x9AD8;&quot;</span>, <span class="hljs-string">&quot;&#x4F53;&#x91CD;&quot;</span>)
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x5217;&#xFF0C;&#x5217;&#x8FD8;&#x4E0D;&#x663E;&#x793A;</span>
  tree.column(<span class="hljs-string">&quot;&#x59D3;&#x540D;&quot;</span>, width=<span class="hljs-number">100</span>)
  tree.column(<span class="hljs-string">&quot;&#x5E74;&#x9F84;&quot;</span>, width=<span class="hljs-number">100</span>)
  tree.column(<span class="hljs-string">&quot;&#x8EAB;&#x9AD8;&quot;</span>, width=<span class="hljs-number">100</span>)
  tree.column(<span class="hljs-string">&quot;&#x4F53;&#x91CD;&quot;</span>, width=<span class="hljs-number">100</span>)

  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x8868;&#x5934;</span>
  tree.heading(<span class="hljs-string">&quot;&#x59D3;&#x540D;&quot;</span>, text=<span class="hljs-string">&quot;&#x59D3;&#x540D;-name&quot;</span>)
  tree.heading(<span class="hljs-string">&quot;&#x5E74;&#x9F84;&quot;</span>, text=<span class="hljs-string">&quot;&#x5E74;&#x9F84;-age&quot;</span>)
  tree.heading(<span class="hljs-string">&quot;&#x8EAB;&#x9AD8;&quot;</span>, text=<span class="hljs-string">&quot;&#x8EAB;&#x9AD8;-height&quot;</span>)
  tree.heading(<span class="hljs-string">&quot;&#x4F53;&#x91CD;&quot;</span>, text=<span class="hljs-string">&quot;&#x4F53;&#x91CD;-weight&quot;</span>)

  <span class="hljs-comment"># &#x6DFB;&#x52A0;&#x6570;&#x636E;</span>
  tree.insert(<span class="hljs-string">&quot;&quot;</span>, <span class="hljs-number">0</span>, text=<span class="hljs-string">&quot;line1&quot;</span>, values=(<span class="hljs-string">&quot;&#x5B5F;&#x5BAA;&#x5CB3;&quot;</span>, <span class="hljs-string">&quot;24&quot;</span>, <span class="hljs-string">&quot;180&quot;</span>, <span class="hljs-string">&quot;135&quot;</span>))
  tree.insert(<span class="hljs-string">&quot;&quot;</span>, <span class="hljs-number">1</span>, text=<span class="hljs-string">&quot;line2&quot;</span>, values=(<span class="hljs-string">&quot;&#x7126;&#x81F4;&#x8FDC;&quot;</span>, <span class="hljs-string">&quot;25&quot;</span>, <span class="hljs-string">&quot;180&quot;</span>, <span class="hljs-string">&quot;150&quot;</span>))

  win.mainloop()
</code></pre>
</li>
<li><h3 id="&#x6811;&#x72B6;&#x7ED3;&#x6784;">&#x6811;&#x72B6;&#x7ED3;&#x6784;</h3>
<p>  ```py</p>
<h1 id="codingutf8-">-<em>- coding:utf-8 -</em>-</h1>
<p>  import tkinter
  from tkinter import ttk</p>
<p>  win = tkinter.Tk()
  win.title(&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;)
  win.geometry(&quot;400x300+200+200&quot;)</p>
</li>
</ul>
<pre><code>tree = ttk.Treeview(win)
tree.pack()

# &#x6DFB;&#x52A0;&#x4E00;&#x7EA7;&#x6811;&#x679D;
treeF1 = tree.insert(&quot;&quot;, 0, &quot;&#x4E2D;&#x56FD;&quot;, text=&quot;&#x4E2D;&#x56FD;CHI&quot;, values=(&quot;F1&quot;))
treeF2 = tree.insert(&quot;&quot;, 1, &quot;&#x7F8E;&#x56FD;&quot;, text=&quot;&#x7F8E;&#x56FD;USA&quot;, values=(&quot;F2&quot;))
treeF3 = tree.insert(&quot;&quot;, 2, &quot;&#x7528;&#x8FC7;&quot;, text=&quot;&#x82F1;&#x56FD;UK&quot;, values=(&quot;F3&quot;))

# &#x6DFB;&#x52A0;&#x4E8C;&#x7EA7;&#x6811;&#x679D;
treeF1_1 = tree.insert(treeF1, 0, &quot;&#x9ED1;&#x9F99;&#x6C5F;&quot;, text=&quot;&#x4E2D;&#x56FD;&#x9ED1;&#x9F99;&#x6C5F;&quot;, values=(&quot;F1_1&quot;))
treeF1_2 = tree.insert(treeF1, 1, &quot;&#x5409;&#x6797;&quot;, text=&quot;&#x4E2D;&#x56FD;&#x5409;&#x6797;&quot;, values=(&quot;F1_2&quot;))
treeF1_3 = tree.insert(treeF1, 2, &quot;&#x8FBD;&#x5B81;&quot;, text=&quot;&#x4E2D;&#x56FD;&#x8FBD;&#x5B81;&quot;, values=(&quot;F1_3&quot;))

treeF2_1 = tree.insert(treeF2, 0, &quot;&#x7EBD;&#x7EA6;&quot;, text=&quot;&#x7F8E;&#x56FD;&#x7EBD;&#x7EA6;&quot;, values=(&quot;F1_1&quot;))
treeF2_2 = tree.insert(treeF2, 1, &quot;&#x65E7;&#x91D1;&#x5C71;&quot;, text=&quot;&#x7F8E;&#x56FD;&#x65E7;&#x91D1;&#x5C71;&quot;, values=(&quot;F1_2&quot;))
treeF2_3 = tree.insert(treeF2, 2, &quot;&#x6D1B;&#x6749;&#x77F6;&quot;, text=&quot;&#x7F8E;&#x56FD;&#x6D1B;&#x6749;&#x77F6;&quot;, values=(&quot;F1_3&quot;))

# &#x4E09;&#x7EA7;&#x6811;&#x679D;
treeF1_1_1 = tree.insert(treeF1_1, 0, &quot;&#x54C8;&#x5C14;&#x6EE8;&quot;, text=&quot;&#x9ED1;&#x9F99;&#x6C5F;&#x54C8;&#x5C14;&#x6EE8;&quot;)
treeF1_1_2 = tree.insert(treeF1_1, 1, &quot;&#x4E94;&#x5E38;&quot;, text=&quot;&#x9ED1;&#x9F99;&#x6C5F;&#x4E94;&#x5E38;&quot;)

win.mainloop()
```
</code></pre><ul>
<li><h3 id="&#x7EDD;&#x5BF9;&#x5E03;&#x5C40;">&#x7EDD;&#x5BF9;&#x5E03;&#x5C40;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  label1 = tkinter.Label(win, text=<span class="hljs-string">&quot;good&quot;</span>, bg=<span class="hljs-string">&quot;blue&quot;</span>)
  label2 = tkinter.Label(win, text=<span class="hljs-string">&quot;nice&quot;</span>, bg=<span class="hljs-string">&quot;red&quot;</span>)
  label3 = tkinter.Label(win, text=<span class="hljs-string">&quot;cool&quot;</span>, bg=<span class="hljs-string">&quot;pink&quot;</span>)

  <span class="hljs-comment"># &#x7EDD;&#x5BF9;&#x5E03;&#x5C40;&#xFF0C;&#x7A97;&#x53E3;&#x7684;&#x53D8;&#x5316;&#x5BF9;&#x4F4D;&#x7F6E;&#x6CA1;&#x6709;&#x5F71;&#x54CD;</span>
  label1.place(x=<span class="hljs-number">10</span>, y=<span class="hljs-number">10</span>)
  label2.place(x=<span class="hljs-number">50</span>, y=<span class="hljs-number">50</span>)
  label3.place(x=<span class="hljs-number">100</span>, y=<span class="hljs-number">100</span>)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="&#x76F8;&#x5BF9;&#x5E03;&#x5C40;">&#x76F8;&#x5BF9;&#x5E03;&#x5C40;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  label1 = tkinter.Label(win, text=<span class="hljs-string">&quot;good&quot;</span>, bg=<span class="hljs-string">&quot;blue&quot;</span>)
  label2 = tkinter.Label(win, text=<span class="hljs-string">&quot;nice&quot;</span>, bg=<span class="hljs-string">&quot;red&quot;</span>)
  label3 = tkinter.Label(win, text=<span class="hljs-string">&quot;cool&quot;</span>, bg=<span class="hljs-string">&quot;pink&quot;</span>)

  <span class="hljs-comment"># &#x76F8;&#x5BF9;&#x5E03;&#x5C40;&#xFF0C;&#x7A97;&#x4F53;&#x6539;&#x53D8;&#x5BF9;&#x63A7;&#x4EF6;&#x6709;&#x5F71;&#x54CD;</span>
  <span class="hljs-comment"># tkinter.BOTH</span>
  <span class="hljs-comment"># label1.pack(fill=tkinter.Y, side=tkinter.LEFT)</span>
  label1.pack(fill=tkinter.Y, side=tkinter.LEFT)
  <span class="hljs-comment"># label2.pack(fill=tkinter.X, side=tkinter.TOP)</span>
  <span class="hljs-comment"># label3.pack(fill=tkinter.Y, side=tkinter.RIGHT)</span>

  win.mainloop()
</code></pre>
</li>
<li><h3 id="&#x8868;&#x683C;&#x5E03;&#x5C40;">&#x8868;&#x683C;&#x5E03;&#x5C40;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  label1 = tkinter.Label(win, text=<span class="hljs-string">&quot;good&quot;</span>, bg=<span class="hljs-string">&quot;blue&quot;</span>)
  label2 = tkinter.Label(win, text=<span class="hljs-string">&quot;nice&quot;</span>, bg=<span class="hljs-string">&quot;red&quot;</span>)
  label3 = tkinter.Label(win, text=<span class="hljs-string">&quot;cool&quot;</span>, bg=<span class="hljs-string">&quot;pink&quot;</span>)
  label4 = tkinter.Label(win, text=<span class="hljs-string">&quot;handsome&quot;</span>, bg=<span class="hljs-string">&quot;yellow&quot;</span>)

  <span class="hljs-comment"># &#x8868;&#x683C;&#x5E03;&#x5C40;</span>
  label1.grid(row=<span class="hljs-number">0</span>, column=<span class="hljs-number">0</span>)
  label2.grid(row=<span class="hljs-number">0</span>, column=<span class="hljs-number">1</span>)
  label3.grid(row=<span class="hljs-number">1</span>, column=<span class="hljs-number">0</span>)
  label4.grid(row=<span class="hljs-number">1</span>, column=<span class="hljs-number">1</span>)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="&#x9F20;&#x6807;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;">&#x9F20;&#x6807;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  <span class="hljs-string">&quot;&quot;&quot;
  &lt;Button-1&gt;          &#x9F20;&#x6807;&#x5DE6;&#x952E;
  &lt;Button-2&gt;          &#x9F20;&#x6807;&#x6ED1;&#x8F6E;
  &lt;Button-3&gt;          &#x9F20;&#x6807;&#x53F3;&#x952E;
  &lt;Double-Button-1&gt;   &#x9F20;&#x6807;&#x5DE6;&#x952E;&#x53CC;&#x51FB;
  &lt;Double-Button-2&gt;   &#x9F20;&#x6807;&#x6ED1;&#x8F6E;&#x53CC;&#x51FB;
  &lt;Double-Button-3&gt;   &#x9F20;&#x6807;&#x53F3;&#x952E;&#x53CC;&#x51FB;
  &lt;Triple-Button-1&gt;   &#x9F20;&#x6807;&#x5DE6;&#x952E;&#x4E09;&#x51FB;
  &lt;Triple-Button-2&gt;   &#x9F20;&#x6807;&#x6ED1;&#x8F6E;&#x4E09;&#x51FB;
  &lt;Triple-Button-3&gt;   &#x9F20;&#x6807;&#x53F3;&#x952E;&#x4E09;&#x51FB;
  &quot;&quot;&quot;</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span><span class="hljs-params">(event)</span>:</span>
      print(event.x, event.y)

  button1 = tkinter.Button(win, text=<span class="hljs-string">&quot;leftmouse button&quot;</span>)
  <span class="hljs-comment"># button1 = tkinter.Label(win, text=&quot;leftmouse button&quot;)</span>
  <span class="hljs-comment"># bind&#xFF0C;&#x7ED9;&#x63A7;&#x4EF6;&#x7ED1;&#x5B9A;&#x4E8B;&#x4EF6;&#xFF0C;&#x53C2;&#x6570;1&#x662F;&#x7ED1;&#x5B9A;&#x7684;&#x4E8B;&#x4EF6;&#xFF0C;&#x53C2;&#x6570;&#x4E8C;&#x662F;&#x89E6;&#x53D1;&#x7684;&#x4E8B;&#x4EF6;&#x6240;&#x5BF9;&#x5E94;&#x6267;&#x884C;&#x7684;&#x51FD;&#x6570;</span>
  <span class="hljs-comment"># button1.bind(&quot;&lt;Button-1&gt;&quot;, func)</span>
  <span class="hljs-comment"># button1.bind(&quot;&lt;Double-Button-1&gt;&quot;, func)</span>
  button1.bind(<span class="hljs-string">&quot;&lt;Button-1&gt;&quot;</span>, func)
  button1.pack()

  win.mainloop()
</code></pre>
</li>
<li><h3 id="&#x9F20;&#x6807;&#x79FB;&#x52A8;&#x4E8B;&#x4EF6;">&#x9F20;&#x6807;&#x79FB;&#x52A8;&#x4E8B;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  <span class="hljs-string">&quot;&quot;&quot;
  &lt;B1-Motion&gt;         &#x8868;&#x793A;&#x5DE6;&#x952E;&#xFF08;&#x6309;&#x4F4F;&#xFF09;&#x79FB;&#x52A8;
  &lt;B2-Motion&gt;         &#x8868;&#x793A;&#x6ED1;&#x8F6E;&#xFF08;&#x6309;&#x4F4F;&#xFF09;&#x79FB;&#x52A8;
  &lt;B3-Motion&gt;         &#x8868;&#x793A;&#x53F3;&#x952E;&#xFF08;&#x6309;&#x4F4F;&#xFF09;&#x79FB;&#x52A8;
  &quot;&quot;&quot;</span>

  label = tkinter.Label(win, text=<span class="hljs-string">&quot;meng is a nice man&quot;</span>)
  label.pack()

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span><span class="hljs-params">(event)</span>:</span>
      print(event.x, event.y)

  label.bind(<span class="hljs-string">&quot;&lt;B2-Motion&gt;&quot;</span>, func)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="&#x9F20;&#x6807;&#x91CA;&#x653E;&#x4E8B;&#x4EF6;">&#x9F20;&#x6807;&#x91CA;&#x653E;&#x4E8B;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  <span class="hljs-string">&quot;&quot;&quot;
  &lt;ButtonReleased-1&gt;      &#x5F53;&#x91CA;&#x653E;&#x9F20;&#x6807;&#x5DE6;&#x952E;&#x65F6;&#x4E8B;&#x4EF6;&#x53D1;&#x751F;
  &lt;ButtonReleased-2&gt;      &#x5F53;&#x91CA;&#x653E;&#x9F20;&#x6807;&#x6ED1;&#x8F6E;&#x65F6;&#x4E8B;&#x4EF6;&#x53D1;&#x751F;
  &lt;ButtonReleased-3&gt;      &#x5F53;&#x91CA;&#x653E;&#x9F20;&#x6807;&#x53F3;&#x952E;&#x65F6;&#x4E8B;&#x4EF6;&#x53D1;&#x751F;
  &quot;&quot;&quot;</span>

  label = tkinter.Label(win, text=<span class="hljs-string">&quot;meng is a nice man&quot;</span>, bg=<span class="hljs-string">&quot;red&quot;</span>)
  label.pack()

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span><span class="hljs-params">(event)</span>:</span>
      print(event.x, event.y)

  label.bind(<span class="hljs-string">&quot;&lt;ButtonRelease-1&gt;&quot;</span>, func)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="&#x9F20;&#x6807;&#x8FDB;&#x5165;&#x79BB;&#x5F00;&#x4E8B;&#x4EF6;">&#x9F20;&#x6807;&#x8FDB;&#x5165;&#x79BB;&#x5F00;&#x4E8B;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  <span class="hljs-string">&quot;&quot;&quot;
  Enter       &#x5F53;&#x9F20;&#x6807;&#x5149;&#x6807;&#x8FDB;&#x5165;&#x63A7;&#x4EF6;&#x5185;&#x89E6;&#x53D1;
  Leave       &#x5F53;&#x9F20;&#x6807;&#x5149;&#x6807;&#x8FDB;&#x5165;&#x63A7;&#x4EF6;&#x5185;&#x89E6;&#x53D1;
  &quot;&quot;&quot;</span>

  label = tkinter.Label(win, text=<span class="hljs-string">&quot;meng is a nice man&quot;</span>, bg=<span class="hljs-string">&quot;red&quot;</span>)
  label.pack()

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span><span class="hljs-params">(event)</span>:</span>
      print(event.x, event.y)

  <span class="hljs-comment"># label.bind(&quot;&lt;Enter&gt;&quot;, func)</span>
  label.bind(<span class="hljs-string">&quot;&lt;Leave&gt;&quot;</span>, func)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="&#x54CD;&#x5E94;&#x6240;&#x6709;&#x7684;&#x6309;&#x952E;&#x4E8B;&#x4EF6;">&#x54CD;&#x5E94;&#x6240;&#x6709;&#x7684;&#x6309;&#x952E;&#x4E8B;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  <span class="hljs-comment"># &lt;Key&gt;     &#x76F8;&#x5E94;&#x6240;&#x6709;&#x7684;&#x6309;&#x952E;</span>
  <span class="hljs-string">&quot;&quot;&quot;
  label = tkinter.Label(win, text=&quot;meng is a nice man&quot;, bg=&quot;red&quot;)
  # &#x8BBE;&#x7F6E;&#x7126;&#x70B9;
  label.focus_set()
  label.pack()

  def func(event):
      print(&quot;event.char = &quot;, event.char)
      print(&quot;event.keycode = &quot;, event.keycode)

  label.bind(&quot;&lt;Key&gt;&quot;, func)
  &quot;&quot;&quot;</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span><span class="hljs-params">(event)</span>:</span>
      print(<span class="hljs-string">&quot;event.char = &quot;</span>, event.char)
      print(<span class="hljs-string">&quot;event.keycode = &quot;</span>, event.keycode)
  win.bind(<span class="hljs-string">&quot;&lt;Key&gt;&quot;</span>, func)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="&#x54CD;&#x5E94;&#x7279;&#x6B8A;&#x6309;&#x952E;&#x4E8B;&#x4EF6;">&#x54CD;&#x5E94;&#x7279;&#x6B8A;&#x6309;&#x952E;&#x4E8B;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  <span class="hljs-comment"># &lt;Shift_L&gt;     &#x5DE6;Shift</span>
  <span class="hljs-comment"># &lt;Shift_R&gt;     &#x53F3;Shift</span>
  <span class="hljs-comment"># &lt;F5&gt;          F5&#x952E;</span>
  <span class="hljs-comment"># &lt;Return&gt;      &#x56DE;&#x8F66;&#x952E;</span>
  <span class="hljs-comment"># &lt;BackSpace&gt;   &#x9000;&#x683C;&#x952E;</span>

  label = tkinter.Label(win, text=<span class="hljs-string">&quot;meng is a nice man&quot;</span>, bg=<span class="hljs-string">&quot;red&quot;</span>)
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x7126;&#x70B9;</span>
  label.focus_set()
  label.pack()

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span><span class="hljs-params">(event)</span>:</span>
      print(<span class="hljs-string">&quot;event.char = &quot;</span>, event.char)
      print(<span class="hljs-string">&quot;event.keycode = &quot;</span>, event.keycode)

  label.bind(<span class="hljs-string">&quot;&lt;BackSpace&gt;&quot;</span>, func)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="&#x6307;&#x5B9A;&#x6309;&#x952E;&#x4E8B;&#x4EF6;">&#x6307;&#x5B9A;&#x6309;&#x952E;&#x4E8B;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span><span class="hljs-params">(event)</span>:</span>
      print(<span class="hljs-string">&quot;event.char = &quot;</span>, event.char)
      print(<span class="hljs-string">&quot;event.keycode = &quot;</span>, event.keycode)

  <span class="hljs-comment"># &#x6307;&#x5B9A;&#x6309;a&#x624D;&#x80FD;&#x54CD;&#x5E94;</span>
  win.bind(<span class="hljs-string">&quot;&lt;a&gt;&quot;</span>, func)

  win.mainloop()
</code></pre>
</li>
<li><h3 id="&#x7EC4;&#x5408;&#x6309;&#x952E;&#x4E8B;&#x4EF6;">&#x7EC4;&#x5408;&#x6309;&#x952E;&#x4E8B;&#x4EF6;</h3>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>

  <span class="hljs-keyword">import</span> tkinter

  win = tkinter.Tk()
  win.title(<span class="hljs-string">&quot;&#x5927;&#x91D1;&#x94FE;&#x5B50;&#x5C0F;&#x624B;&#x8868;&quot;</span>)
  win.geometry(<span class="hljs-string">&quot;400x300+200+200&quot;</span>)

  <span class="hljs-string">&quot;&quot;&quot;
  &lt;Control-Alt-a&gt;
  &lt;Shift-Up&gt;
  &lt;Control-p&gt;
  &quot;&quot;&quot;</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span><span class="hljs-params">(event)</span>:</span>
      print(<span class="hljs-string">&quot;event.char = &quot;</span>, event.char)
      print(<span class="hljs-string">&quot;event.keycode = &quot;</span>, event.keycode)

  <span class="hljs-comment"># &#x6307;&#x5B9A;&#x7EC4;&#x5408;&#x6309;&#x952E;&#x54CD;&#x5E94;</span>
  <span class="hljs-comment"># win.bind(&quot;&lt;Control-Alt-a&gt;&quot;, func)</span>
  win.bind(<span class="hljs-string">&quot;&lt;Shift-Up&gt;&quot;</span>, func)

  win.mainloop()
</code></pre>
</li>
</ul>
<hr>
<ul>
<li><h1 id="&#x9F20;&#x6807;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;">&#x9F20;&#x6807;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;</h1>
<p><img src="../images/&#x9F20;&#x6807;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;.png" alt=""></p>
</li>
<li><h1 id="&#x70B9;&#x51FB;&#x4EA7;&#x751F;&#x65F6;&#x95F4;&#x5C5E;&#x6027;">&#x70B9;&#x51FB;&#x4EA7;&#x751F;&#x65F6;&#x95F4;&#x5C5E;&#x6027;</h1>
<p><img src="../images/&#x70B9;&#x51FB;&#x4EA7;&#x751F;&#x65F6;&#x95F4;&#x5C5E;&#x6027;.png" alt=""></p>
</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../home/8.面向对象/7.模块和包.html" class="navigation navigation-prev " aria-label="Previous page: 模块和包"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../home/10.网络编程/1.网络编程.html" class="navigation navigation-next " aria-label="Next page: 网络编程"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
